define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'resume/basicinfo/index' + location.search,
                    preview_url: 'resume/resume/preview',
                    add_url: 'resume/basicinfo/add',
                    edit_url: 'resume/resume/edit',
                    del_url: 'resume/basicinfo/del',
                    multi_url: 'resume/basicinfo/multi',
                    import_url: 'resume/basicinfo/import',
                    table: 'resume_basicinfo',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'BasicinfoID',
                sortName: 'BasicinfoID',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'BasicinfoID', title: __('Basicinfoid')},
                        {field: 'Name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'Gender', title: __('Gender'), searchList: {"1":__('Gender 1'),"2":__('Gender 2')}, formatter: Table.api.formatter.normal},
                        {field: 'WorkYear', title: __('Workyear'), operate:'BETWEEN'},
                        {field: 'EducationCategory', title: __('Educationcategory'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'JobSearchStatus', title: __('Jobsearchstatus'), searchList: {"1":__('Jobsearchstatus 1'),"2":__('Jobsearchstatus 2'),"3":__('Jobsearchstatus 3'),"4":__('Jobsearchstatus 4')}, formatter: Table.api.formatter.status},
                        {field: 'Remark', title: __('Remark'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'CreatedTime', title: __('Createdtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'UpdatedTime', title: __('Updatedtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            buttons: [
                                {
                                    name: 'preview',
                                    title: function (row) {
                                        return row.Name+'的简历预览';
                                    },
                                    classname: 'btn btn-xs btn-info btn-addtabs',
                                    icon: 'fa fa-file-text-o',
                                    url: $.fn.bootstrapTable.defaults.extend.preview_url,
                                },
                                {
                                    name: 'download',
                                    title: '下载',
                                    classname: 'btn btn-xs btn-info',
                                    icon: 'fa fa-download',
                                    url: $.fn.bootstrapTable.defaults.extend.preview_url+"?download=1",
                                },
                                {
                                    name: 'edit',
                                    title: function (row) {
                                        return '编辑'+row.Name+'的简历';
                                    },
                                    classname: 'btn btn-xs btn-success btn-addtabs',
                                    extend: "data-area='[\"90%\", \"90%\"]'",
                                    icon: 'fa fa-pencil',
                                    url: function (row, j) {
                                        return $.fn.bootstrapTable.defaults.extend.edit_url + '?BasicinfoID=' + row.BasicinfoID;
                                    },
                                }
                            ],
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
            // 初始化表格参数配置
            Table.api.init();
            Controller.api.buildTable.careerobjective();
            Controller.api.buildTable.education();
            Controller.api.buildTable.workexp();
            Controller.api.buildTable.projectexperience();
            Controller.api.buildTable.schoolexperience();
            Controller.api.buildTable.trophy();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            buildTable: {
                basicinfo: function () {

                    var table = $("#basicinfo-table");

                    // 初始化表格
                    table.bootstrapTable({
                        url: 'resume/basicinfo/index' + location.search,
                        extend: {
                            index_url: 'resume/basicinfo/index' + location.search,
                            edit_url: 'resume/basicinfo/edit' + location.search,
                            table: 'resume_basicinfo',
                        },
                        toolbar: '#basicinfo-toolbar',
                        pk: 'BasicinfoID',
                        sortName: 'BasicinfoID',
                        fixedColumns: true,
                        fixedRightNumber: 1,
                        templateView: true,
                        templateFormatter: 'basicinfotpl',
                        //禁用默认搜索
                        search: false,
                        commonSearch: false,
                        searchFormVisible: false,
                        showExport: false,
                        showToggle: false,
                        showColumns: false,
                        pagination: false,
                        columns: [
                            [
                                {checkbox: true},
                                {field: 'BasicinfoID', title: __('ID')},
                                {field: 'Name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                                {field: 'WorkYear', title: __('Workyear'), operate:'BETWEEN'},
                                {field: 'CurrentLocation', title: __('Currentlocation'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                                {field: 'MaritalStatus', title: __('Maritalstatus'), searchList: {"1":__('Maritalstatus 1'),"2":__('Maritalstatus 2'),"3":__('Maritalstatus 3')}, formatter: Table.api.formatter.status},
                                {field: 'EducationCategory', title: __('Educationcategory'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                                {field: 'JobSearchStatus', title: __('Jobsearchstatus'), searchList: {"1":__('Jobsearchstatus 1'),"2":__('Jobsearchstatus 2'),"3":__('Jobsearchstatus 3'),"4":__('Jobsearchstatus 4')}, formatter: Table.api.formatter.status},
                            ]
                        ]
                    });

                    // 为表格绑定事件
                    Table.api.bindevent(table);
                },
                careerobjective: function () {
                    var table = $("#careerobjective-table");

                    // 初始化表格
                    table.bootstrapTable({
                        url: 'resume/careerobjective/index' + location.search,
                        extend: {
                            index_url: 'resume/careerobjective/index' + location.search,
                            add_url: 'resume/careerobjective/add' + location.search,
                            edit_url: 'resume/careerobjective/edit' + location.search,
                            del_url: 'resume/careerobjective/del' + location.search,
                            multi_url: 'resume/careerobjective/multi' + location.search,
                            import_url: 'resume/careerobjective/import' + location.search,
                            table: 'resume_career_objective',
                        },
                        toolbar: '#careerobjective-toolbar',
                        pk: 'ObjectiveID',
                        sortName: 'ObjectiveID',
                        fixedColumns: true,
                        fixedRightNumber: 1,
                        //禁用默认搜索
                        search: false,
                        commonSearch: false,
                        searchFormVisible: false,
                        showExport: false,
                        showToggle: false,
                        showColumns: false,
                        pagination: false,
                        columns: [
                            [
                                {checkbox: true},
                                {field: 'ObjectiveID', title: __('ID')},
                                {field: 'BasicinfoID', title: __('Basicinfoid'), visible: false},
                                {field: 'AccommodationRequired', title: __('Accommodationrequired'), searchList: {"1":__('Accommodationrequired 1'),"0":__('Accommodationrequired 0')}, formatter: Table.api.formatter.normal},
                                {field: 'AvailabilityDay', title: __('Availabilityday'), searchList: {"7":__('Availabilityday 7'),"14":__('Availabilityday 14'),"30":__('Availabilityday 30'),"60":__('Availabilityday 60'),"90":__('Availabilityday 90'),"255":__('Availabilityday 255')}, formatter: Table.api.formatter.normal},
                                {field: 'ExpectedJobFunction', title: __('Expectedjobfunction'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                                {field: 'ExpectedJobIndustry', title: __('Expectedjobindustry'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                                {field: 'ExpectedJobLocation', title: __('Expectedjoblocation'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                                {field: 'ExpectedSalary', title: __('Expectedsalary')},
                                {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                            ]
                        ]
                    });

                    // 为表格绑定事件
                    Table.api.bindevent(table);
                },
                education: function () {
                    var table = $("#education-table");

                    // 初始化表格
                    table.bootstrapTable({
                        toolbar: '#education-toolbar',
                        url: 'resume/education/index' + location.search,
                        extend: {
                            index_url: 'resume/education/index' + location.search,
                            add_url: 'resume/education/add' + location.search,
                            edit_url: 'resume/education/edit' + location.search,
                            del_url: 'resume/education/del' + location.search,
                            multi_url: 'resume/education/multi' + location.search,
                            import_url: 'resume/education/import' + location.search,
                            table: 'resume_education',
                        },
                        pk: 'EducationID',
                        sortName: 'StartDate',
                        fixedColumns: true,
                        fixedRightNumber: 1,
                        //禁用默认搜索
                        search: false,
                        commonSearch: false,
                        searchFormVisible: false,
                        showExport: false,
                        showToggle: false,
                        showColumns: false,
                        pagination: false,
                        columns: [
                            [
                                {checkbox: true},
                                {field: 'EducationID', title: __('ID')},
                                {field: 'BasicinfoID', title: __('Basicinfoid'), visible: false},
                                {field: 'StartDate', title: __('Startdate'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                                {field: 'EndDate', title: __('Enddate'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                                {field: 'SchoolName', title: __('Schoolname'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                                {field: 'Major', title: __('Major'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                                {field: 'EducationLevel', title: __('Educationlevel'), searchList: {"10":__('Educationlevel 10'),"20":__('Educationlevel 20'),"30":__('Educationlevel 30'),"40":__('Educationlevel 40'),"50":__('Educationlevel 50'),"60":__('Educationlevel 60'),"70":__('Educationlevel 70'),"80":__('Educationlevel 80')}, formatter: Table.api.formatter.normal},
                                {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                            ]
                        ]
                    });

                    // 为表格绑定事件
                    Table.api.bindevent(table);
                },
                workexp: function () {
                    var table = $("#workexp-table");

                    // 初始化表格
                    table.bootstrapTable({
                        url: 'resume/workexp/index' + location.search,
                        extend: {
                            index_url: 'resume/workexp/index' + location.search,
                            add_url: 'resume/workexp/add' + location.search,
                            edit_url: 'resume/workexp/edit' + location.search,
                            del_url: 'resume/workexp/del' + location.search,
                            multi_url: 'resume/workexp/multi' + location.search,
                            import_url: 'resume/workexp/import' + location.search,
                            table: 'resume_workexp',
                        },
                        toolbar: '#workexp-toolbar',
                        pk: 'WorkexpID',
                        sortName: 'StartDate',
                        fixedColumns: true,
                        fixedRightNumber: 1,
                        //禁用默认搜索
                        search: false,
                        commonSearch: false,
                        searchFormVisible: false,
                        showExport: false,
                        showToggle: false,
                        showColumns: false,
                        pagination: false,
                        columns: [
                            [
                                {checkbox: true},
                                {field: 'WorkexpID', title: __('ID')},
                                {field: 'BasicinfoID', title: __('Basicinfoid'), visible: false},
                                {field: 'StartDate', title: __('StartDate'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                                {field: 'EndDate', title: __('Enddate'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                                {field: 'Company', title: __('Company'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                                {field: 'JobFunction', title: __('Jobfunction'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                                {field: 'JobIndustry', title: __('Jobindustry'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                                {field: 'Title', title: __('Title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                                {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                            ]
                        ]
                    });

                    // 为表格绑定事件
                    Table.api.bindevent(table);
                },
                projectexperience: function () {

                    var table = $("#projectexperience-table");

                    // 初始化表格
                    table.bootstrapTable({
                        toolbar: '#projectexperience-toolbar',
                        url: 'resume/projectexperience/index' + location.search,
                        extend: {
                            index_url: 'resume/projectexperience/index' + location.search,
                            add_url: 'resume/projectexperience/add' + location.search,
                            edit_url: 'resume/projectexperience/edit' + location.search,
                            del_url: 'resume/projectexperience/del' + location.search,
                            multi_url: 'resume/projectexperience/multi' + location.search,
                            import_url: 'resume/projectexperience/import' + location.search,
                            table: 'resume_project_experience',
                        },
                        pk: 'ExperienceID',
                        sortName: 'StartDate',
                        //禁用默认搜索
                        search: false,
                        commonSearch: false,
                        searchFormVisible: false,
                        showExport: false,
                        showToggle: false,
                        showColumns: false,
                        pagination: false,
                        columns: [
                            [
                                {checkbox: true},
                                {field: 'ExperienceID', title: __('ID')},
                                {field: 'BasicinfoID', title: __('Basicinfoid'), visible: false},
                                {field: 'StartDate', title: __('Startdate'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                                {field: 'EndDate', title: __('Enddate'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                                {field: 'ProjectName', title: __('Projectname'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                                {field: 'ProjectDuty', title: __('Projectduty'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                                {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                            ]
                        ]
                    });

                    // 为表格绑定事件
                    Table.api.bindevent(table);
                },
                schoolexperience: function () {
                    var table = $("#schoolexperience-table");

                    // 初始化表格
                    table.bootstrapTable({
                        toolbar: '#schoolexperience-toolbar',
                        url: 'resume/schoolexperience/index' + location.search,
                        extend: {
                            index_url: 'resume/schoolexperience/index' + location.search,
                            add_url: 'resume/schoolexperience/add' + location.search,
                            edit_url: 'resume/schoolexperience/edit' + location.search,
                            del_url: 'resume/schoolexperience/del' + location.search,
                            multi_url: 'resume/schoolexperience/multi' + location.search,
                            import_url: 'resume/schoolexperience/import' + location.search,
                            table: 'resume_school_experience',
                        },
                        pk: 'SchoolExperienceID',
                        sortName: 'StartDate',
                        columns: [
                            [
                                {checkbox: true},
                                {field: 'SchoolExperienceID', title: __('Schoolexperienceid')},
                                {field: 'BasicinfoID', title: __('Basicinfoid')},
                                {field: 'StartDate', title: __('Startdate'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                                {field: 'EndDate', title: __('Enddate'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                                {field: 'Title', title: __('Title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                                {field: 'Duty', title: __('Duty'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                                {field: 'Description', title: __('Description'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                                {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                            ]
                        ]
                    });

                    // 为表格绑定事件
                    Table.api.bindevent(table);
                },
                trophy: function () {
                    var table = $("#trophy-table");
                    // 初始化表格
                    table.bootstrapTable({
                        toolbar: '#trophy-toolbar',
                        url: 'resume/trophy/index' + location.search,
                        extend: {
                            index_url: 'resume/trophy/index' + location.search,
                            add_url: 'resume/trophy/add' + location.search,
                            edit_url: 'resume/trophy/edit' + location.search,
                            del_url: 'resume/trophy/del' + location.search,
                            multi_url: 'resume/trophy/multi' + location.search,
                            import_url: 'resume/trophy/import' + location.search,
                            table: 'resume_trophy',
                        },
                        pk: 'TrophyID',
                        sortName: 'Date',
                        //禁用默认搜索
                        search: false,
                        commonSearch: false,
                        searchFormVisible: false,
                        showExport: false,
                        showToggle: false,
                        showColumns: false,
                        pagination: false,
                        columns: [
                            [
                                {checkbox: true},
                                {field: 'TrophyID', title: __('Trophyid')},
                                {field: 'BasicinfoID', title: __('Basicinfoid'), visible: false},
                                {field: 'Date', title: __('Date'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                                {field: 'Title', title: __('Title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                                {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                            ]
                        ]
                    });
                    // 为表格绑定事件
                    Table.api.bindevent(table);
                },
            }
        }
    };
    return Controller;
});
